<script setup lang="ts">
import MedicalOrderDetail from './components/MedicalORderDetail.vue'
// 引入组合式函数
import { useOrderDetail } from '@/composables'
import { OrderType } from '@/enums';
import router from '@/router';
import { useRoute } from 'vue-router'
const route = useRoute()
const { medOrderDetail } = useOrderDetail(route.params.id as string)
console.log(medOrderDetail)
</script>

<template>
    <div class="order-detail-page" v-if="medOrderDetail">
        <cp-nav-bar :title="`药品订单详情-${medOrderDetail?.statusValue}`" />
        <div class="order-head">
            <!-- 默认的收货地址 -->
            <div class="address" v-if="medOrderDetail?.status === OrderType.MedicineCancel ||
                medOrderDetail?.status === OrderType.MedicinePay ||
                medOrderDetail?.status === OrderType.MedicineSend">
                <p class="area">
                    <van-icon name="location" />
                    <span>{{
                        medOrderDetail.addressInfo.province +
                        medOrderDetail.addressInfo.city +
                        medOrderDetail.addressInfo.county
                    }}</span>
                </p>
                <p class="detail">{{ medOrderDetail.addressInfo.addressDetail }}</p>
                <p>{{ medOrderDetail.addressInfo.receiver }}
                    {{
                        medOrderDetail.addressInfo.mobile.replace(
                            /^(\d{3})\d{4}(\d{4})$/,
                            '$1****$2'
                        )
                    }}
                </p>
            </div>
            <div class="card" v-else @click="router.push(`/order/logistics/${medOrderDetail?.id}`)">
                <div class="logistics">
                    <p>{{ medOrderDetail?.expressInfo.content }}</p>
                    <p>{{ medOrderDetail?.expressInfo.time }}</p>
                </div>
                <van-icon name="arrow" />
            </div>
        </div>
        <MedicalOrderDetail :medicines="medOrderDetail?.medicines"></MedicalOrderDetail>

        <div class="order-detail">
            <van-cell-group>
                <van-cell title="药品金额" :value="`￥${medOrderDetail?.actualPayment}`" />
                <van-cell title="运费" :value="`￥${medOrderDetail?.expressFee}`" />
                <van-cell title="优惠券" :value="`-￥${medOrderDetail?.couponDeduction}`" />
                <van-cell title="实付款" :value="`￥${medOrderDetail?.payment}`" class="price" />
                <van-cell title="订单编号" :value="medOrderDetail?.orderNo" />
                <van-cell title="创建时间" :value="medOrderDetail?.createTime" />
                <template v-if="
                    medOrderDetail?.status === OrderType.MedicineSend ||
                    medOrderDetail?.status === OrderType.MedicineTake ||
                    medOrderDetail?.status === OrderType.MedicineComplete
                ">
                    <van-cell title="支付时间" :value="medOrderDetail.payTime" />
                    <van-cell title="支付方式" :value="medOrderDetail.paymentMethod === 0 ? '微信支付' : '支付宝支付'
                        " />
                </template>
            </van-cell-group>
        </div>
        <!-- 已取消 -->
        <van-action-bar v-if="medOrderDetail?.status === OrderType.MedicineCancel">
            <van-action-bar-icon icon="delete-o" text="删除" />
            <van-action-bar-button type="primary" text="沟通记录" />
        </van-action-bar>
        <!-- 待收货 -->
        <van-action-bar v-if="medOrderDetail?.status === OrderType.MedicineTake">
            <van-action-bar-button type="primary" text="确认收货" />
        </van-action-bar>
        <!-- 待发货 -->
        <van-action-bar v-if="medOrderDetail?.status === OrderType.MedicineSend">
            <van-action-bar-button type="primary" text="提醒发货" />
        </van-action-bar>
        <!-- 待支付 -->
        <van-action-bar v-if="medOrderDetail?.status === OrderType.MedicinePay">
            <p class="price">需要支付：<span>￥60</span></p>
            <van-action-bar-button color="#bbb" text="取消订单" />
            <van-action-bar-button type="primary" text="继续支付" />
        </van-action-bar>
        <!-- 已完成 -->
        <van-action-bar v-if="medOrderDetail?.status === OrderType.MedicineComplete">
            <van-action-bar-icon icon="delete-o" text="删除" />
            <van-action-bar-button type="primary" text="再次购买" />
        </van-action-bar>
    </div>
    <!-- 骨架屏效果 -->
    <div class="order-detail-page" v-else>
        <cp-nav-bar title="药品订单详情" />
        <van-skeleton title :row="2" style="margin-top: 15px" />
        <van-skeleton title :row="4" style="margin-top: 30px" />
        <van-skeleton title :row="4" style="margin-top: 30px" />
    </div>
</template>

<style lang="scss" scoped>
.order-detail-page {
    padding-top: 46px;
    padding-bottom: 65px;
}

.address {
    padding: 15px;
    background-color: #fff;
    font-size: 13px;
    position: relative;
    box-shadow: 0px 0px 22px 0px rgba(229, 229, 229, 0.5);
    border-radius: 8px;

    .area {
        color: var(--cp-tag);
        margin-bottom: 5px;

        .van-icon-location {
            color: #ff7702;
            font-size: 14px;
        }
    }

    .detail {
        font-size: 17px;
        margin-bottom: 5px;
    }
}

.order-head {
    position: relative;
    padding: 15px;

    &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 80px;
        background: linear-gradient(180deg,
                rgba(44, 181, 165, 0),
                rgba(44, 181, 165, 0.2));
        border-bottom-left-radius: 150px 20px;
        border-bottom-right-radius: 150px 20px;
    }

    .card {
        height: 74px;
        background-color: #fff;
        border-radius: 8px;
        position: relative;
        display: flex;
        align-items: center;
        padding: 0 15px;
        box-shadow: 0px 0px 22px 0px rgba(229, 229, 229, 0.5);

        .logistics {
            flex: 1;

            p {
                &:first-child {
                    color: var(--cp-primary);
                }

                &:last-child {
                    color: var(--cp-tag);
                    font-size: 13px;
                    margin-top: 5px;
                }
            }
        }

        .van-icon {
            color: var(--cp-tip);
        }
    }
}

:deep(.van-cell) {
    .van-cell__title {
        font-size: 14px;
        flex: none;
        width: 100px;
    }

    .van-cell__value {
        font-size: 14px;
    }

    &.price {
        .van-cell__value {
            font-size: 18px;
            color: var(--cp-price);
        }
    }
}

.van-action-bar {
    padding: 0 10px;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.1);

    .price {
        padding: 0 10px;

        >span {
            font-size: 18px;
            color: var(--cp-price);
        }
    }
}
</style>